/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tree;

/**
 *
 * @author Ej-Dý
 */
public class WriteTree extends VlastniProgramTree {
private VyrazTree expression;

private boolean line;

    public WriteTree(Position start, Position end,VyrazTree expression) {
        super(start, end);
        
        this.expression = expression;
    }

    public VyrazTree getExpression() {
        return expression;
    }

    public void setExpression(VyrazTree expression) {
        this.expression = expression;
    }

    @Override
    public void accept(TreeVisitor visitor) {
        visitor.visitWriteln(this);
    }

    @Override
    public void generate(Context ctx) {
        //ctx.println("getstatic java/lang/System/out Ljava/io/PrintStream;");
        if(expression.getType()!=Type.STRING){
            expression.setType(Type.CONV);
        }
        //expression.setType(Type.CONV);
        expression.generate(ctx);
        //switch (expression.getType()) {
          //  case INTEGER:
            //    ctx.println("invokevirtual java/io/PrintStream/println(I)V");
            //    break;
          //  case REAL:
           //     ctx.println("invokevirtual java/io/PrintStream/println(D)V");
       // }
        if(line){
           ctx.println("writeln 0"); 
        }else{
            ctx.println("write 0");
        }
        
    }
    @Override
    public String toString() {
        return String.format("Writeln %s: [%s]", super.toString(), expression);
    }

    /**
     * @return the line
     */
    public boolean isLine() {
        return line;
    }

    /**
     * @param line the line to set
     */
    public void setLine(boolean line) {
        this.line = line;
    }
    
}

    
